<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>添加管理员</title>  <link rel="icon" href="/template/pc1/images/wmh_favicon.ico" type="image/x-icon" />
    <meta name="author" content="yeshop Team" />
    <meta name="copyright" content="yeshop" />
    <link rel="icon" href="">
    <link href="https://static.9hive.cn/global/vendor/bootstrap-3.3.7/bootstrap.min.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/nprogress/nprogress.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/fonts/font-awesome/font-awesome.min.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/icheck/icheck.min.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/animate/animate.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/bootstrap-table-1.11/bootstrap-table.min.css?v=1.1" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/common/common_20170925.css" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/inside/inside.css?v=1" rel="stylesheet">
    <link href="https://static.9hive.cn/global/vendor/file/file.css" rel="stylesheet">
    <script type="text/javascript">
        function save() {
            var username=$("input[name='username']").val().trim();
            var password=$("input[name='password']").val().trim();
            var rePassword=$("input[name='rePassword']").val().trim();
            var email=$("input[name='email']").val().trim();
            var userimgurl=$("input[name='userimgurl']").val().trim();
            var roleId=$("select[name='roleId']").val().trim();
            var shopId=$("input[name='shopId']").val();
            var brandStoreId=$("select[name='brandStoreId']").val();
            if(!username){
                layer.msg("用户名不允许为空");
                return;
            }
            if(!password){
                layer.msg("密码不允许为空");
                return;
            }
            if(!rePassword){
                layer.msg("重复密码不允许为空");
                return;
            }
            if(!email){
                layer.msg("E-mail不允许为空");
                return;
            }

            $.ajax({
                url: "${base}/shop/user/save",
                type: 'GET',
                data:{
                    "username":username,
                    "password":password,
                    "rePassword":rePassword,
                    "email":email,
                    "roleId":roleId,
                    "shopId":shopId,
                    "brandStoreId":brandStoreId,
                    "userimgurl":userimgurl
                },
                success: function(data){
                    if(data.code == 1){
                        //注册错误
                        layer.msg(data.desc);
                    }else if (data.code == 0){
                        window.location.href="${base}/shop/user/list";
                    }
                }});
        }

        function update() {
            var memberId="${member.id!}";
            var password=$("input[name='password']").val().trim();
            var rePassword=$("input[name='rePassword']").val().trim();
            var email=$("input[name='email']").val().trim();
            var userimgurl=$("input[name='userimgurl']").val().trim();
            var roleId=$("select[name='roleId']").val().trim();
            var brandStoreId=$("select[name='brandStoreId']").val();
            if(!email){
                layer.msg("E-mail不允许为空");
                return;
            }

            $.ajax({
                url: "${base}/shop/user/update",
                type: 'GET',
                data:{
                    "memberId":memberId,
                    "password":password,
                    "rePassword":rePassword,
                    "email":email,
                    "roleId":roleId,
                    "brandStoreId":brandStoreId,
                    "userimgurl":userimgurl
                },
                success: function(data){
                    if(data.code == 1){
                        //注册错误
                        layer.msg(data.desc);
                    }else if (data.code == 0){
                        window.location.href="${base}/shop/user/list";
                    }
                }});
        }
    </script>
    <%
    var isAdd = false;
    var isEdit = false;
    if(isEmpty(member.id)){
    isAdd = true;
    }else{
    isEdit = true;
    }
    %>
<body class="white-bg">
<div class="wrapper wrapper-content ibox float-e-margins">
    <div class="ibox-title">
        <div class="pull-left mbx">
            权限管理<span class="line">/</span>
            <a href="/shop/user/list" class="mbxsecond">账号管理</a><span class="line">/</span>
            <span class="current"><%if(isAdd){%>添加管理员<%}else{%>编辑管理员<%}%></span>
        </div>
    </div>
    <div class="ibox-content">
        <form method="post" action="<%if (isAdd){%>${base}/shop/user/save<%}else{%>${base}/shop/user/update<%}%>" class="form-horizontal form-validate">
            <input type="hidden" name="shopId" value="${shopId!}"/>
            <input type="hidden" name="memberId" value="${member.id!}"/>
            <div class="form-group">
                <label class="col-sm-2 control-label">登录名：</label>
                <div class="col-sm-3">
                    <%if (isAdd){%>
                    <input type="text" name="username" value="${member.username!}" class="form-control input-sm" required="true">
                    <%}else{%>
                    ${member.username!}
                    <input type="hidden" name="username" class="form-control input-sm" value="${member.username!}" />
                    <%}%>
                </div>
                <span class="help-block"><span class="maroon">*</span></span>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">密码：</label>
                <div class="col-sm-3">
                    <%if(isAdd){%>
                        <input type="password" name="password" value="" class="form-control input-sm" required="true">
                    <%}else{%>
                        <input type="password" name="password" value="" class="form-control input-sm">
                    <%}%>
                </div>
                <%if(isAdd){%>
                    <span class="help-block"><span class="maroon">*</span></span>
                <%}%>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">重复密码：</label>
                <div class="col-sm-3">
                    <%if(isAdd){%>
                        <input type="password" name="rePassword" value="" class="form-control input-sm" required="true">
                    <%}else{%>
                        <input type="password" name="rePassword" value="" class="form-control input-sm">
                    <%}%>
                </div>
                    <%if(isAdd){%>
                        <span class="help-block"><span class="maroon">*</span></span>
                    <%}%>
            </div>
            <!--<div class="form-group">
                <label class="col-sm-2 control-label">品牌商名称：</label>
                <div class="col-sm-3">
                    <input type="text" name="brandName" value="${member.brandName!}" class="form-control input-sm" required="true">
                </div>
                <span class="help-block"><span class="maroon">*</span></span>
            </div>-->
            <!--<div class="form-group">
                <label class="col-sm-2 control-label">品牌商类目：</label>
                <div class="col-sm-10">
                    <div class="row">
                        <div class="col-sm-2">
                            <select name="category_one" class="form-control" id="category_one" ></select>
                        </div>
                        <div class="col-sm-2">
                            <select name="category_two" class="form-control" id="category_two" ></select>
                        </div>

                        <script src="/res/plugins/jiuyue/category_select.js"></script>
                        <script type="text/javascript">
                            new category('category_one', 'category_two', '${category_one!}', '${category_two!}');
                        </script>
                    </div>
                </div>
            </div>-->

            <div class="form-group">
                <label class="col-sm-2 control-label">E-mail: </label>
                <div class="col-sm-3">
                    <input type="text" name="email" value="${member.email!}" class="form-control input-sm">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">头像:</label>
                <div class="col-sm-3">
                    <input type="hidden" name="userimgurl" value="" class="pull-left form-control input-sm"/>
                    <img class="img-rounded" src="${member.userimgurl!}" style="max-height:50px;"/>
                    <input type="button" class="button browserButton" value="选择文件"/>
                    <span class="help-block"><span class="maroon"></span>建议300*300像素；格式jpg</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">角色：</label>
                <div class="col-sm-3">
                    <select name="roleId" value="${member.roleId!}" class="form-control input-sm" style="height: 31px">
                        <%for(list in roleList){%>
                        <option value="${list.id}" <%if (list.id == member.roleId!){%> selected<%}%>>
                        ${list.name}
                        </option>
                        <%}%>
                    </select>
                </div>
            </div>
            <%if(isNotEmpty(brandStoreList)){%>
            <div class="form-group">
                <label class="col-sm-2 control-label">所属门店：</label>
                <div class="col-sm-3">
                    <select name="brandStoreId" value="" class="form-control input-sm" style="height: 31px">
                        <option value="">请选择</option>
                        <%for(list in brandStoreList!){%>
                        <option value="${list.id}" <%if (list.id == member.brandStoreId!){%> selected<%}%>>
                        ${list.business_name}
                        </option>
                        <%}%>
                    </select>
                </div>
            </div>
            <%}%>
            <div class="form-group">
                <div class="col-sm-4 col-sm-offset-2">
                    <input type="submit" class="btn btn-primary" value="提交保存" />
                    <button class="btn btn-white" onclick="history.back()" type="button">取消</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="https://static.9hive.cn/global/vendor/jquery/jquery-2.1.4.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/nprogress/nprogress.js"></script>
<script src="https://static.9hive.cn/global/vendor/bootstrap-3.3.7/bootstrap.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/jquery-validate/jquery.validate.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/jquery-validate/additional-methods.min.js"></script>

<script src="https://static.9hive.cn/global/vendor/jquery-validate/localization/messages_zh.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/jquery-ajaxform/ajax-form.js"></script>
<script src="https://static.9hive.cn/global/vendor/bootstrap-table-1.11/bootstrap-table.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/bootstrap-table-1.11/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="https://static.9hive.cn/global/vendor/layer/layer.js"></script>
<!-- 自定义js -->
<script src="https://static.9hive.cn/global/vendor/inside/inside20170925.js"></script>
<script src="https://static.9hive.cn/global/vendor/file/uploadify/jquery_uploadify.js"></script>

<script type="text/javascript">
    var uploadUrl="/file/uploadfile?shopId=${shopId!}&type=d";
    var browserUrl="/file/browser?shopId=${shopId!}";
</script>
<script src="https://static.9hive.cn/global/vendor/file/file.js"></script>
<script type="text/javascript">
    $(function () {
        $("input.browserButton").browser();
    })
</script>
</body>

</html>